package com.parttime.actions;

import java.io.IOException;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;

import com.parttime.beans.Merchant_Users;
import com.parttime.service.MerchantUsersManager;
import com.parttime.service.PersonalUsersManager;

@ParentPackage("merchant_users")
@Namespace("/")
@ExceptionMappings({@ExceptionMapping(exception = "java.lange.RuntimeException", result = "error")})
public class Merchant_UsersAction extends CommonAction {
	@Autowired
	private MerchantUsersManager merchantUsersManager;
	@Autowired
	private PersonalUsersManager personalUsersManager;
	private Merchant_Users merchant_user;
	@Action(value="register")
	public void Register() throws IOException{
		System.out.print(merchant_user);
		try{
			merchant_user.setStatus("0");
			merchantUsersManager.register(merchant_user);
			
			
			response.getWriter().print(true);
		}catch(Exception e){
			e.printStackTrace();
			response.getWriter().print(false);
		}
	}
	
	@Action(value="validateEmail")
	public void validateEmail()throws Exception{
		String phone=request.getParameter("phone");
		String email=request.getParameter("email");
		String msg=merchantUsersManager.validateEmail(phone,email);
		response.setCharacterEncoding("utf-8");
		response.getWriter().print(msg);
	
		
	}
	
	@Action(value="/resetPassword")
	public void resetPassword() throws IOException{
		request.setCharacterEncoding("utf-8");
		String phone=request.getParameter("phone");
		String password=request.getParameter("password");
	    if(!merchantUsersManager.resetPassword(phone,password)){
	    	response.getWriter().print("保存密码错误");
	    }
	}
	
	public Merchant_Users getMerchant_user() {
		return merchant_user;
	}
	public void setMerchant_user(Merchant_Users merchant_user) {
		this.merchant_user = merchant_user;
	}
	


}
